import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/bezier_bounce_footer.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/bezier_circle_header.dart';
import 'package:wanchong/conf.dart';

class Rank extends StatefulWidget {
  @override
  _RankState createState() => _RankState();
}

class _RankState extends State<Rank> {

  final TextStyle redStyle = TextStyle(
    fontSize: 14.0,
    color: const Color(0xFFFF5D64)
  );
  final TextStyle blueStyle = TextStyle(
    fontSize: 14.0,
    color: const Color(0xFF2494FF)
  );
  List<RankDetail> mData = List();
  GlobalKey<EasyRefreshState> _easyRefreshKey =
      new GlobalKey<EasyRefreshState>();
  GlobalKey<RefreshHeaderState> _headerKey =
      new GlobalKey<RefreshHeaderState>();
  GlobalKey<RefreshFooterState> _footerKey =
      new GlobalKey<RefreshFooterState>();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        leading: Icon(Icons.chevron_left),
        title: Center(
          child: Text(
            "积分记录",
            style: TextStyle(
              color: Color(MainColor),
              fontSize: ScreenUtil.getInstance().setSp(18),
            ),
          ),
        ),
      ),
      body: Center(
        child: EasyRefresh(
          key: _easyRefreshKey,
          behavior: ScrollOverBehavior(),
          refreshHeader: BezierCircleHeader(
            key: _headerKey,
            backgroundColor: Color(0xFFFFCC33),
          ),
          refreshFooter: BezierBounceFooter(
            key: _footerKey,
            backgroundColor: Color(0xFFFFCC33),
          ),
          onRefresh: () async {
            await new Future.delayed(const Duration(seconds: 1), () {
              setState(() {
                // str.clear();
                // str.addAll(addStr);
              });
            });
          },
          loadMore: () async {
            await new Future.delayed(const Duration(seconds: 1), () {
              // if (str.length < 20) {
              //   setState(() {
              //     str.addAll(addStr);
              //   });
              // }
            });
          },
          child: ListView.builder(
            itemBuilder: (BuildContext context, int index) {
              return Container(
                color: Colors.white,
                height: ScreenUtil.getInstance().setHeight(72.0),
                padding: EdgeInsets.only(left: 15.0, right: 15.0),
                child: Column(
                  // crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    SizedBox(
                      height: 15.0,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(
                          "每日签到积分",
                          style: TextStyle(
                            color: Color(MainColor),
                            fontSize: ScreenUtil.getInstance().setSp(14.0),
                          ),
                        ),
                        Text(index%2==0?(-index-index~/2).toString():"+"+(index-index~/2).toString(),style: index%2==0?redStyle:blueStyle,),
                      ],
                    ),
                    Container(
                      child: Text(
                        "2015-5.12",
                        style: TextStyle(
                          color: Color(0xFFB4BEC6),
                          fontSize: ScreenUtil.getInstance().setSp(12.0),
                        ),
                      ),
                      width: double.infinity,
                    ),
                    SizedBox(
                      height: ScreenUtil.getInstance().setHeight(14.0),
                    ),
                    Divider(
                      color: Color(BorderColor),
                      height: ScreenUtil.getInstance().setHeight(1.0),
                    ),
                  ],
                ),
              );
            },
            itemCount: 60,
          ),
        ),
      ),
    );
  }
}

class RankDetail {
  String title;
  int point;
  String time;
  RankDetail({this.title, this.point, this.time});
}
